/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MantenimientoDePersonas.java
 *
 * Created on 14-may-2012, 0:24:48
 */
package Interfaz_Grafica;

import Logica.LPersonas;
import Objetos.Personas;
import java.awt.Component;
import java.awt.Window;
import java.awt.event.WindowEvent;
import java.beans.Statement;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Omar Heráclides
 */
public class MantenimientoDePersonas extends javax.swing.JFrame {

    private Component parent;
    private Boolean modificable;
    private int CodigoPersona;
   
    static Statement stmt = null;
    static Connection con = null;
    private int fila = -1;
    private String mensajeValidacion = "";

    public String getMensajeValidacion() {
        return mensajeValidacion;
    }

    public void setMensajeValidacion(String mensajeValidacion) {
        this.mensajeValidacion = mensajeValidacion;
    }

    public int getFila() {
        return fila;
    }

    public void setFila(int fila) {
        this.fila = fila;
    }

    public void setCodigoPersona(int CodigoPersona) {
        this.CodigoPersona = CodigoPersona;
    }

    public int getCodigoPersona() {
        return CodigoPersona;
    }

    public Boolean getModificable() {
        return modificable;
    }

    public final void setModificable(Boolean modificable) {
        this.modificable = modificable;
    }

    /** Creates new form MantenimientoDePersonas */
    public MantenimientoDePersonas() {
        this.setTitle("Mantenimiento de Personas");
        initComponents();
       
// Evita que el Frame padre obtenga el foco 
        setModificable(false);
        DefaultTableModel dtm = new DefaultTableModel();
        String titulos[] = {"Codigo", "Nombre", "Ap. Paterno", "Ap. Materno", "DNI", "Fecha Nacimiento", "Sexo"};
        dtm.setColumnIdentifiers(titulos);
        dtmTablaPersonas.setModel(dtm);
        
      setDefaultCloseOperation(DISPOSE_ON_CLOSE); 
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel6 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        txtNombre = new java.awt.TextField();
        txtApPaterno = new java.awt.TextField();
        txtApMaterno = new java.awt.TextField();
        txtDNI = new java.awt.TextField();
        label1 = new java.awt.Label();
        label2 = new java.awt.Label();
        label3 = new java.awt.Label();
        lblMaterno = new java.awt.Label();
        lblMaterno1 = new java.awt.Label();
        lblMaterno2 = new java.awt.Label();
        txtFechaNacimiento = new java.awt.TextField();
        jcbSexo = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        list1 = new java.awt.List();
        jScrollPane1 = new javax.swing.JScrollPane();
        dtmTablaPersonas = new javax.swing.JTable();
        lblBuscarPersona = new java.awt.Button();
        txtBuscarPersona = new java.awt.TextField();
        jButton3 = new javax.swing.JButton();
        btnModificarPersonal = new javax.swing.JButton();
        jcbBuscar = new javax.swing.JComboBox();
        btnLimpiarTexboxs = new javax.swing.JButton();

        jLabel6.setText("jLabel6");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Mantenimiento de Personas"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        label1.setText("Nombre:");

        label2.setText("Apellido Paterno:");

        label3.setText("Apellido Materno:");

        lblMaterno.setText("DNI :");

        lblMaterno1.setText("Sexo :");

        lblMaterno2.setText("Fecha de Nacimiento :");

        jcbSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "M", "F" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(148, 148, 148)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(75, 75, 75)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtApPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtApMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtDNI, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtFechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jcbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addComponent(lblMaterno1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblMaterno2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(25, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(1, 1, 1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtApPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(1, 1, 1)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtApMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(2, 2, 2)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDNI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblMaterno1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblMaterno2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jcbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtFechaNacimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(32, Short.MAX_VALUE))
        );

        label1.getAccessibleContext().setAccessibleName("lblNombre");
        lblMaterno.getAccessibleContext().setAccessibleName("");

        jButton1.setText("Eliminar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Limpiar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        list1.setMultipleMode(true);
        list1.setName("lblLista"); // NOI18N
        list1.setVisible(false);

        dtmTablaPersonas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        dtmTablaPersonas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dtmTablaPersonasMouseClicked(evt);
            }
        });
        dtmTablaPersonas.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                dtmTablaPersonasKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                dtmTablaPersonasKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(dtmTablaPersonas);

        lblBuscarPersona.setLabel("Buscar :");
        lblBuscarPersona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                lblBuscarPersonaActionPerformed(evt);
            }
        });

        txtBuscarPersona.setName("lblBuscar:"); // NOI18N

        jButton3.setText("Agregar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        btnModificarPersonal.setText("Modificar");
        btnModificarPersonal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModificarPersonalActionPerformed(evt);
            }
        });

        jcbBuscar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "DNI", "Apellido Paterno" }));

        btnLimpiarTexboxs.setText("Limpiar");
        btnLimpiarTexboxs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarTexboxsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(list1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addGap(563, 563, 563))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 411, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnModificarPersonal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btnLimpiarTexboxs, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
                        .addContainerGap(40, Short.MAX_VALUE))))
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblBuscarPersona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(65, 65, 65)
                        .addComponent(txtBuscarPersona, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(jcbBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(172, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(list1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(64, 64, 64)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lblBuscarPersona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtBuscarPersona, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jcbBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnModificarPersonal)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnLimpiarTexboxs)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(41, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    int resp;
    Boolean validPage = true;
    validPage = ValidarPagina();

    resp = JOptionPane.showConfirmDialog(null, "¿Desea Agregar el registro?", "Pregunta", 0);
    if (validPage) {
        if (resp == 0) {
                try {
                    LimpiarTabla();
                    Personas objPersona = new Personas();

                    objPersona.setIdPersona(this.botenerIDPersona());
                    objPersona.setDNI(txtDNI.getText());
                    objPersona.setNombre(txtNombre.getText());
                    objPersona.setApPaterno(txtApPaterno.getText());
                    objPersona.setApMaterno(txtApMaterno.getText());
                    objPersona.setSexo(jcbSexo.getSelectedItem().toString().charAt(0));
                    objPersona.setFecha(txtFechaNacimiento.getText());

                    this.limpiar();
                    LPersonas objLpersonas = new LPersonas();
                    String mensaje = "Fallo";
                    try {
                        mensaje = objLpersonas.AgregarPersona(objPersona);
                    } catch (SQLException ex) {
                        Logger.getLogger(MantenimientoDePersonas.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    JOptionPane.showMessageDialog(null, mensaje,
                            "Información", JOptionPane.INFORMATION_MESSAGE);
                } catch (SQLException ex) {
                    Logger.getLogger(MantenimientoDePersonas.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
    } else {
        JOptionPane.showMessageDialog(null, this.getMensajeValidacion(),
                "Información", JOptionPane.INFORMATION_MESSAGE);
    }
}//GEN-LAST:event_jButton3ActionPerformed


private void lblBuscarPersonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lblBuscarPersonaActionPerformed

    LPersonas objLpersona = new LPersonas();
    String DNI;

    if (txtBuscarPersona.getText().equals("") == true) {
        try {
            dtmTablaPersonas.setModel(objLpersona.MostrarPersonas());
        } catch (SQLException ex) {
            Logger.getLogger(MantenimientoDePersonas.class.getName()).log(Level.SEVERE, null, ex);
        }

    } else {

        try {
            dtmTablaPersonas.setModel(objLpersona.SelectPersonas(this.txtBuscarPersona.getText(), this.jcbBuscar.getSelectedItem().toString()));
        } catch (SQLException ex) {
            Logger.getLogger(MantenimientoDePersonas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


}//GEN-LAST:event_lblBuscarPersonaActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
    LimpiarTabla();
    this.setFila(-1);
    this.txtBuscarPersona.setText("");
    this.setModificable(false);

}//GEN-LAST:event_jButton2ActionPerformed

private void btnModificarPersonalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarPersonalActionPerformed
// TODO add your handling code here:
    int resp;
    if (this.modificable == true) {
        resp = JOptionPane.showConfirmDialog(null, "¿Desea Modificar el registro?", "Pregunta", 0);
        if (resp == 0) {
            LimpiarTabla();
            Personas objPersonas = new Personas();
            objPersonas.setIdPersona(this.getCodigoPersona());
            objPersonas.setApMaterno(this.txtApMaterno.getText());
            objPersonas.setApPaterno(this.txtApPaterno.getText());
            objPersonas.setDNI(this.txtDNI.getText());
            objPersonas.setFecha(this.txtFechaNacimiento.getText());
            objPersonas.setNombre(this.txtNombre.getText());
            objPersonas.setSexo(this.jcbSexo.getSelectedItem().toString().charAt(0));
            this.limpiar();

            LPersonas objLpersonas = new LPersonas();
            String mensaje = "Fallo";
            try {
                mensaje = objLpersonas.ModificarPersona(objPersonas);
            } catch (SQLException ex) {
                Logger.getLogger(MantenimientoDePersonas.class.getName()).log(Level.SEVERE, null, ex);
            }
            JOptionPane.showMessageDialog(null, mensaje,
                    "Información", JOptionPane.INFORMATION_MESSAGE);
        }
        this.setModificable(false);
        this.limpiar();
    } else {
        JOptionPane.showMessageDialog(null, "Debe selecionar un registro de la tabla!", "Información", JOptionPane.INFORMATION_MESSAGE);
    }
}//GEN-LAST:event_btnModificarPersonalActionPerformed

private void dtmTablaPersonasKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dtmTablaPersonasKeyReleased
}//GEN-LAST:event_dtmTablaPersonasKeyReleased

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    int resp;
    LPersonas objPersona = new LPersonas();
    String mensaje = "";
    int codigo;
    if (this.modificable == true) {
        resp = JOptionPane.showConfirmDialog(null, "¿Desea Eliminar el registro?", "Pregunta", 0);
        if (resp == 0) {
            int row = this.getFila();
            if (row >= 0) {
                // JOptionPane.showMessageDialog(this, this.dtmTablaPersonas.getValueAt(row, 0));
                codigo = Integer.parseInt((String) this.dtmTablaPersonas.getValueAt(row, 0));
                try {
                    mensaje = objPersona.Eliminar(codigo);
                } catch (SQLException ex) {
                    Logger.getLogger(MantenimientoDePersonas.class.getName()).log(Level.SEVERE, null, ex);
                }

                this.LimpiarTabla();
            }
        } else {
            mensaje = "Debe de selecionar una Fila!";
        }
    } else {
        JOptionPane.showMessageDialog(this, mensaje);
    }

}//GEN-LAST:event_jButton1ActionPerformed

private void dtmTablaPersonasKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dtmTablaPersonasKeyPressed
// TODO add your handling code here:
}//GEN-LAST:event_dtmTablaPersonasKeyPressed

private void dtmTablaPersonasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dtmTablaPersonasMouseClicked
// TODO add your handling code here:

    int row = this.dtmTablaPersonas.rowAtPoint(evt.getPoint());
    if (row >= 0) {
        this.setModificable(true);
        this.setFila(row);
        //String titulos[] = {"Codigo", "Nombre", "Ap. Paterno", "Ap. Materno", "DNI", "Fecha Nacimiento", "Sexo"};
        this.txtApMaterno.setText(this.dtmTablaPersonas.getModel().getValueAt(row, 3).toString());
        this.txtApPaterno.setText(this.dtmTablaPersonas.getModel().getValueAt(row, 2).toString());
        this.txtDNI.setText(this.dtmTablaPersonas.getModel().getValueAt(row, 4).toString());
        this.txtFechaNacimiento.setText(this.dtmTablaPersonas.getModel().getValueAt(row, 5).toString());
        this.txtNombre.setText(this.dtmTablaPersonas.getModel().getValueAt(row, 1).toString());
        this.jcbSexo.setSelectedItem(this.dtmTablaPersonas.getModel().getValueAt(row, 6).toString());
        this.setCodigoPersona(Integer.parseInt(this.dtmTablaPersonas.getModel().getValueAt(row, 0).toString()));
    } else {
        this.setModificable(false);
    }


}//GEN-LAST:event_dtmTablaPersonasMouseClicked

private void btnLimpiarTexboxsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarTexboxsActionPerformed
// TODO add your handling code here:
    limpiar();

}//GEN-LAST:event_btnLimpiarTexboxsActionPerformed

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
// TODO add your handling code here:

}//GEN-LAST:event_formWindowClosed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// T*ODO add your handling code here:
   
}//GEN-LAST:event_formWindowClosing
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLimpiarTexboxs;
    private javax.swing.JButton btnModificarPersonal;
    private javax.swing.JTable dtmTablaPersonas;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox jcbBuscar;
    private javax.swing.JComboBox jcbSexo;
    private java.awt.Label label1;
    private java.awt.Label label2;
    private java.awt.Label label3;
    private java.awt.Button lblBuscarPersona;
    private java.awt.Label lblMaterno;
    private java.awt.Label lblMaterno1;
    private java.awt.Label lblMaterno2;
    private java.awt.List list1;
    private java.awt.TextField txtApMaterno;
    private java.awt.TextField txtApPaterno;
    private java.awt.TextField txtBuscarPersona;
    private java.awt.TextField txtDNI;
    private java.awt.TextField txtFechaNacimiento;
    private java.awt.TextField txtNombre;
    // End of variables declaration//GEN-END:variables

    private void limpiar() {
        this.txtApMaterno.setText("");
        this.txtApPaterno.setText("");
        this.txtDNI.setText("");
        this.txtFechaNacimiento.setText("");
        this.txtNombre.setText("");
    }

    private void LimpiarTabla() {
        LPersonas objLpersona = new LPersonas();
        this.dtmTablaPersonas.setModel(objLpersona.LimpiarTabla());
    }

    private Integer botenerIDPersona() throws SQLException {
        LPersonas objLpersona = new LPersonas();
        return objLpersona.ObtenerIdPersona();

    }

    private Boolean ValidarPagina() {
        boolean v;
        String mensajeValidacion = "";

        if (IsLetra(this.txtApMaterno.getText()) == false) {
            mensajeValidacion = "Ingrese solo carateres en el campo Apellido Materno";
            this.setMensajeValidacion(mensajeValidacion);
            return false;
        }
        if (IsLetra(this.txtApPaterno.getText()) == false) {
            mensajeValidacion = "Ingrese solo carateres en el campo Apellido Paterno";
            this.setMensajeValidacion(mensajeValidacion);
            return false;
        }
        if (IsLetra(this.txtNombre.getText()) == false) {
            mensajeValidacion = "Ingrese solo carateres en el campo Nombre";
            this.setMensajeValidacion(mensajeValidacion);
            return false;
        }
        if (IsNumber(this.txtDNI.getText()) == false) {
            mensajeValidacion = "Ingrese solo número en el campo DNI";
            this.setMensajeValidacion(mensajeValidacion);
            return false;
        }
        if (IsDate(this.txtFechaNacimiento.getText()) == false) {
            mensajeValidacion = "Ingrese el formato de fecha correcto en el Campo Fecha";
            this.setMensajeValidacion(mensajeValidacion);
            return false;
        }
        
        
        return true;
    }

    private boolean IsLetra(String palabra) {

        for (int i = 0; i < palabra.length(); i++) {
            if (!((palabra.charAt(i) > 64 && palabra.charAt(i) < 91)
                    || (palabra.charAt(i) > 96 && palabra.charAt(i) < 123))) {
                return false;
            }
        }
        return true;
    }

    private boolean IsNumber(String cad) {

        for (int i = 0; i < cad.length(); i++) {
            if (!Character.isDigit(cad.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    public boolean IsDate(String fechax) {
        try {
            SimpleDateFormat formatoFecha = new SimpleDateFormat("yyyy-mm-dd");
            Date fecha = formatoFecha.parse(fechax);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
